package copyengine.ui.tooltips
{
	import flash.display.MovieClip;
	import flash.display.Stage;
	import flash.geom.Rectangle;

	public final class CEToolTipsLayoutHelper
	{
		/**
		 *定义鼠标外轮廓大小(ToolTips会围绕鼠标轮廓)
		 */
		private static const MOUSE_BOUND_WIDHT:int = 8;
		private static const MOUSE_BOUND_HEIGHT:int = 15;

		private var stage:Stage;

		public function CEToolTipsLayoutHelper()
		{
		}

		public function initialize(_stage:Stage):void
		{
			stage = _stage;
		}

		public function layoutTipsMc(_tipsMc:MovieClip,
									 _stageMousePosX:int,
									 _stageMousePosY:int):void
		{
			var leftTopPosX:int;
			var leftTopPosY:int;
			//Tooltips在鼠标的左边
			if (_stageMousePosX + MOUSE_BOUND_WIDHT + _tipsMc.width > stage.stageWidth)
			{
				leftTopPosX = _stageMousePosX - _tipsMc.width;
			}
			//Tooltips在鼠标的右边
			else
			{
				leftTopPosX = _stageMousePosX + MOUSE_BOUND_WIDHT;
			}
			//ToolTips在鼠标上边
			if (_stageMousePosY + MOUSE_BOUND_HEIGHT + _tipsMc.height > stage.stageHeight)
			{
				leftTopPosY = _stageMousePosY - _tipsMc.height;
			}
			//Tooltips在鼠标的下边
			else
			{
				leftTopPosY = _stageMousePosY + MOUSE_BOUND_HEIGHT;
			}

			var toolTipsRe:Rectangle = _tipsMc.getBounds(stage);
			_tipsMc.x += leftTopPosX - toolTipsRe.left;
			_tipsMc.y += leftTopPosY - toolTipsRe.top;
		}

	}
}